﻿using Com.ThrongIn.BE;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Collections.Generic;
using System;

namespace Com.ThrongIn.DAL
{
    public class CategoryDAL
    {
        public List<Category> GetCategoryForBreadCrumb(Int64 categoryId)
        {
            DbParameter[] param = new DbParameter[1];
            param[0] = DBInstance.ParameterInstance(DbType.Int64, "in_category_id", categoryId, ParameterDirection.Input);
            List<Category> categoryList = new List<Category>();
            using (IDataReader reader = DBInstance.GetReader(StoredProc.GET_GETCATEGORYTREE, param))
            {
                Category category = null;
                while(reader.Read())
                {
                    category = new Category();
                    DBInstance.PopulateEntity<Category>(category, reader);
                    categoryList.Add(category);
                }
                return categoryList;
            }

        }
        /// <summary>
        /// Get Menu
        /// </summary>
        /// <returns></returns>
        public DataSet GetMenu()
        {
            DataSet ds = new DataSet();
            ds = DBInstance.GetDataSet(StoredProc.GET_MENUITEMS);
            ds.DataSetName = "Menus";
            ds.Tables[0].TableName = "Menu";           
            
            DataRelation dr = new DataRelation("ParentChild", ds.Tables["Menu"].Columns["category_mst_id"], ds.Tables["Menu"].Columns["parent_category_id"]);
            dr.Nested = true;
            ds.Relations.Add(dr);
            return ds;
        }
    }
}
